// 模拟数据
import mockjs from 'mockjs';

export function setupMock() {
  // 可选：设置全局延迟，模拟网络时延
  mockjs.setup({ timeout: '200-600' });

  // 标记启用 Mock，供网络层决策走 XHR
  if (typeof window !== 'undefined') {
    window.__MOCK_ENABLED__ = true;
  }

  // 列表数据
  mockjs.mock('/api/demo/list', 'get', () => {
    return mockjs.mock({
      code: 0,
      message: 'ok',
      data: {
        'list|10-20': [
          {
            'id|+1': 1,
            name: '@cname',
            'age|18-60': 1
          }
        ]
      }
    });
  });

  // 详情
  mockjs.mock('/api/demo/detail', 'get', () => {
    return mockjs.mock({
      code: 0,
      message: 'ok',
      data: {
        id: '@integer(1, 1000)',
        name: '@cname',
        age: '@integer(18, 60)',
        desc: '@cparagraph(2,4)'
      }
    });
  });

  // 新增
  mockjs.mock('/api/demo/create', 'post', () => {
    return { code: 0, message: 'ok', data: true };
  });

  // 更新
  mockjs.mock('/api/demo/update', 'put', () => {
    return { code: 0, message: 'ok', data: true };
  });

  // 删除
  mockjs.mock('/api/demo/delete', 'delete', () => {
    return { code: 0, message: 'ok', data: true };
  });
}

export default mockjs;